'''
Encoding converter plugin for gedit application
Copyright (C) 2009  Alexey Kuznetsov <ak@axet.ru>
Copyright (C) 2011  Krzysztof Dryja <cih997@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

from gi.repository import GObject, Gtk, Gdk, Gedit
from gencodingconverter import EncodingConverterPluginHelper
from configuredialog import ConfigureDialog

class EncodingConverterPlugin(GObject.Object, Gedit.WindowActivatable):
  __gtype_name__ = "EncodingConverterPlugin"

  window = GObject.property(type=Gedit.Window)
  
  def __init__(self):
    GObject.Object.__init__(self)
    self.instances = {}

  def do_activate(self):
    self.instances[self.window] = EncodingConverterPluginHelper(self, self.window, self.plugin_info.get_data_dir())

  def do_deactivate(self):
    self.instances[self.window].close()
    del self.instances[self.window]

  def update_ui(self, window):
    self.instances[window].update_ui()

  def reload_ui(self):
    for enc in self.instances:
      self.instances[enc].load_menus()

  def create_configure_dialog(self):
    window = GObject.app_get_default().get_active_window()
    cd = ConfigureDialog(window, self)
    return cd["dialog"]
